import { createApp } from "vue"
import { createPinia } from "pinia"
import { createRouter, createWebHistory } from "vue-router"
import App from "./App.vue"
import routes from "./router/index"
import { useAuthStore } from "./stores/auth"
import './style.css'
import 'remixicon/fonts/remixicon.css'

const router = createRouter({
  history: createWebHistory(),
  routes,
})

const pinia = createPinia()

// 路由守卫
router.beforeEach((to, from, next) => {
  const authStore = useAuthStore()

  if (to.meta.requiresAuth && !authStore.isAuthenticated) {
    next("/login")
  } else if (to.path === "/login" && authStore.isAuthenticated) {
    next("/jobs")
  } else {
    next()
  }
})

const app = createApp(App)
app.use(pinia)
app.use(router)
app.use((window as Window & typeof globalThis & {Quasar: any}).Quasar, {config:{
  notify: (window as Window & typeof globalThis & {Quasar: any}).Quasar.Notify
}})
app.mount("#app")
